package panel.stars
{
	import flash.display.Bitmap;
	import flash.display.Sprite;
	
	public class Star extends Sprite
	{
		public static const FULL_STAR:uint = 1;
		public static const HALF_STAR:uint = 2;
		public static const EMPTY_STAR:uint = 0;
		
		[Embed(source = "../../assets/public/starEmpty.png")]
		private var starEmpty:Class;
		[Embed(source = "../../assets/public/starFull.png")]
		private var starFull:Class;
		[Embed(source = "../../assets/public/starHalf.png")]
		private var starHalf:Class;
		
		protected var _showPic:Bitmap;
		private var _type:uint;
		public function Star(type:uint)
		{
			super();
			init(type);
		}
		
		/**
		 * 
		 * @param type 穿入默认值 是可以改变星星
		 * 
		 */		
		public function changeType(type:uint = 3):void
		{
			if(type == 3)//3类型为将星星改成相反状态 如满星变空星
			{
				_type = Math.abs(_type - 1);
			}else
			{
				_type = type;
			}
			if(_showPic)
			{
				clear();
				//				_showPic.bitmapData.dispose();
			}
			if(_type == EMPTY_STAR)
			{
				_showPic = new starEmpty();
			}else if(_type == FULL_STAR)
			{
				_showPic = new starFull();
			}else if(_type == HALF_STAR)
			{
				_showPic = new starHalf();
				_showPic.x = _showPic.x - 1;
				_showPic.y = _showPic.y + 1;
			}
			this.addChild(_showPic);
		}
		
		public function get level():uint
		{
			return _type;
		}
		
		public function init(type:uint):void
		{
			changeType(type);
			this.addChild(_showPic);
		}
		
		public function clear():void
		{
			if(_showPic){
				_showPic.bitmapData.dispose();
				this.removeChild(_showPic);
				_showPic = null;
			}
		}
		
	}
}